package com.gyd.marte;

import java.util.ArrayList;

import com.gyd.dto.Empresa;
import com.gyd.pojos.promociones;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ItemPromoAdapter extends BaseAdapter {
	  protected Activity activity;
	  protected ArrayList<promociones> items;
	         
	  public ItemPromoAdapter(Activity activity, ArrayList<promociones> items) {
	    this.activity = activity;
	    this.items = items;
	  }
	 
	  @Override
	  public int getCount() {
	    return items.size();
	  }
	 
	  @Override
	  public Object getItem(int position) {
	    return items.get(position);
	  }
	 
	  @Override
	  public long getItemId(int position) {
	    return items.get(position).getId();
	  }
	 
	  @Override
	  public View getView(int position, View convertView, ViewGroup parent) {
	    View vi=convertView;
	         
	    if(convertView == null) {
	      LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	      vi = inflater.inflate(R.layout.list_item_layout, null);
	    }
	             
	    promociones item = items.get(position);
	         
	    ImageView image = (ImageView) vi.findViewById(R.id.imagen);
	    int imageResource = activity.getResources().getIdentifier(item.getRutaImagen(), null, activity.getPackageName());
	    image.setImageDrawable(activity.getResources().getDrawable(imageResource));
	         
	    TextView nombre = (TextView) vi.findViewById(R.id.nombre);
	    nombre.setText(item.getNombre());
	         
	    TextView direccion = (TextView) vi.findViewById(R.id.direccion);
	    direccion.setText(item.getPrecio());
	 
	    return vi;
	  }
	}
